package com.ssi.mrms.converter;

import java.util.Map;

import org.apache.struts2.util.StrutsTypeConverter;

public class StringToIntConverter extends StrutsTypeConverter {

	public Object convertFromString(@SuppressWarnings("rawtypes") Map context, String[] strings,
			@SuppressWarnings("rawtypes") Class toClass) {
		if (strings == null || strings.length == 0 || strings[0].trim().length() == 0) {
			return 0;
		}
		return Integer.valueOf(strings[0]);
	}

	public String convertToString(@SuppressWarnings("rawtypes") Map context, Object i) {
		if (i != null && i instanceof Integer) {
			return i.toString();
		} else {
			return null;
		}
	}

}
